
package com.itheima.app.exception;

import com.itheima.vo.ErrorResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice //说明对controller进行了增强 异常处理类
public class GlobalExceptionAdvice {

    @ExceptionHandler(Exception.class)//处理所有的异常
    public ResponseEntity handlerException(Exception ex){
        //输出异常信息
        ex.printStackTrace();

        //提示用户
        return ResponseEntity.status(500).body(ErrorResult.error());
    }

    @ExceptionHandler(BusinessExcepiton.class)
    public ResponseEntity handlerBusinessException(Exception ex){
        //输出异常信息
        System.out.println(ex.getMessage());

        //提示用户
        return ResponseEntity.status(500).body(ex.getMessage());
    }

}
